package org.bozo.im.service.protocols.xmpp.util.jid;

public class JID {

	private String mJID;
	private String mNode;
	private String mDomain;
	private String mRessource;

	public JID(String pJID) {
		update(pJID);
	}

	public void update(String pJID) {
		mJID = pJID;

		if (pJID.contains("@")) {
			mNode = pJID.substring(0, pJID.indexOf('@'));
			pJID = pJID.substring(pJID.indexOf('@') + 1);
		}

		if (pJID.contains("/")) {
			mRessource = pJID.substring(pJID.indexOf('/') + 1);
			pJID = pJID.substring(0, pJID.indexOf('/'));
		}

		mDomain = pJID;
	}

	public String getJID() {
		return mJID;
	}

	public String getNode() {
		return mNode;
	}

	public String getRessource() {
		return mRessource;
	}

	public String getDomain() {
		return mDomain;
	}

	public String getLoginName() {
		StringBuilder lBuilder = new StringBuilder();
		lBuilder.append(mNode).append('@').append(mDomain);
		return lBuilder.toString();
	}

	@Override
	public String toString() {
		return mJID;
	}
}
